﻿using CatUtils.Utils.Currency;
using CatUtils.Utils.Currency.IoUtils;
using CatUtils.Utils.Currency.TextUtils;
using CatUtils.Utils.Helper;
using CatUtils.Utils.SpecialUtils.Html;
using CatUtilsDll.Utils.Currency.WebUtils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LineStickerDwonload.Linehelper
{
    internal class ExcavateDownload
    {
        public void StartDownload(List<String> ScannerList)
        {
            int Complted = 0;
            foreach (var item in ScannerList)
            {
                if (item == "")
                    continue;
                Console.WriteLine($"当前下载{Complted++}，总计{ScannerList.Count}");
                DownloadSingle(item);
            }
        }

        /// <summary>
        /// 下载单个表情包
        /// </summary>
        /// <param name="ComicLink"></param>
        private void DownloadSingle(string ComicLink)
        {
            string Shtml = Transcoding.HtmlDecode(WebHelper.HttpPcGet(ComicLink));
            string FloderPath = LineTool.GetFloderPath(Shtml);

            List<LineTool.DownloadInfo> downloads = LineTool.AnalysisImg(Shtml);
            foreach (var item in downloads)
            {
                new WebHelper().DownloadToFile(item.FileLink, FloderPath + item.FileName);
            }
        }
    }
}